package artid.com.arttogoa.task;

/*******************************************************************************
 * Copyright (c) 2014 by ehoo Corporation all right reserved.
 * 2014-4-18 
 * 
 *******************************************************************************/

import org.apache.http.entity.StringEntity;

import android.annotation.SuppressLint;
import android.content.Context;

import artid.com.arttogoa.util.NetUtils;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;


/**
 * <pre>
 * 功能说明: 
 * 日期:	2014-4-18
 * 开发者:	王耀龙
 * 
 * 历史记录
 *    修改内容：
 *    修改人员：
 *    修改日期： 2014-4-18
 * </pre>
 */
@SuppressLint("ShowToast")
public class NearHttpClient {

	/**
	 * 功能说明： 日期: 2014-4-18 开发者:
	 * 
	 * @param args
	 * 
	 * 
	 */
//	private static ThreadPoolExecutor cacheThreadPool;
	private static AsyncHttpClient client;
	private static boolean boo = false;
	private static String Token;
	static int i = 0;
	static {
		client = new AsyncHttpClient();
//		cacheThreadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
//		client.setThreadPool(cacheThreadPool);
		client.setTimeout(10000);
		client.addHeader("content-type", "application/x-www-form-urlencoded");
//		client.addHeader("content-encoding", "utf-8");
		client.addHeader("Accept", "application/json, text/javascript, */*");
	}

	@SuppressLint("ShowToast")
	public static void get(Context context, String url, RequestParams params,
			NearHttpResponseHandler responseHandler) {
		if (context != null && !NetUtils.isNetworkConnected(context)) {
			return;
		}

		client.get(url, params, responseHandler);
	}

	public static void post(Context context, String url, RequestParams params,
			JsonHttpResponseHandler responseHandler) {
//		responseHandler.setContext(context);
//		responseHandler.setUrl(url);
//		responseHandler.setNearHttpResponseHandler(responseHandler);
		client.post(context, url, params, responseHandler);
		// (context, url, params, "application/json", responseHandler);
	}

	public static void cPost(Context context, String url, StringEntity params,
			JsonHttpResponseHandler responseHandler) {
		client.post(context, url, params, "application/json", responseHandler);
	}

	public static void cancelRequest(Context context) {
		client.cancelRequests(context, true);
	}
}
